<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8"%>
<% String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="renderer" content="webkit">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>社会关系/家庭成员</title>
	<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
	<div>
		<div class="sqPanel">
			<div class="sqPanel_head inL">
				<div class="btnsBox inLC">
					<span id="cst_rl_add_btn" class="sq-button sq-button-round">添加</span>
					<span id="cst_rl_modify_btn" class="sq-button sq-button-round">修改</span>
					<span id="cst_rl_qd_btn" class="sq-button sq-button-round" onclick="selectQd();">确定</span>
					<!-- <span id="cst_rl_detail_btn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_2"></i>详情</span> -->
				</div>
				<span>社会关系/家庭成员</span>
			</div>
			<div class="sqPanel_body">
				<div id="ligergrid_A1" class="sq-grid"></div>
			</div>
		</div>
	</div>
</div>
<script>
    var npSocialRlGrid;//自然人关系Grid
    var cstId = '${cstId}';
    $(function() {
        //确定按钮
        lkType = '${lkType}';
        if(lkType == '1'){
            $("#cst_rl_qd_btn").hide();
        }
        initData();//初始化数据
        initEvent();//初始化事件
    });

    //初始化数据
    function initData(){
        initCstRlGrid();//初始化社会关系
    }

    //初始化事件
    function initEvent(){
        cstRlAddBtnEvent();
        cstRlModifyBtnEvent();
    }

    //初始化社会关系
    function initCstRlGrid() {
        $("#ligergrid_A1").ligerGrid({
            usePager: false,
            url: '<%=path%>/customer/cstnpsocialrl/initList.do?cstId='+cstId,
            method : 'get',
            columns: [{
                display: '关系',
                name: 'rlTypCdNm',
                isSort: false,
                width: 120,render: function (rowdata, rowindex, value, column) {
                    var h = '';
                    if(rowdata.rlTypCd != "7"){
                        if(StringUtils.isEmpty(value)){
                            value = "";
                        }
                        h='<a  href="javascript:cstRlDetailBtnEvent(';
                        h+="'"+rowdata.id+"'";
                        h+=')">'+value+'</a>'
                    }else{
                        h = value;
                    }
                    return h;
                }
            }, {
                display: '姓名',
                name: 'rlNm',
                isSort: false,
                minWidth: 60,
                align:'center',render: function (rowdata, rowindex, value, column) {
                    if(StringUtils.isEmpty(value)){
                        value = "";
                    }
                    var h = value;
                    if(StringUtils.isNotEmpty(rowdata.rlCstId)){
                        h='<a  href="javascript:toCstDetailBtnEvent(';
                        h+="'"+rowdata.rlCstId+"'";
                        h+=')">'+value+'</a>'
                    }
                    return h;
                }
            }, {
                display: '手机号',
                name: 'mp',
                isSort: false,
                width: 150,
            }, /* {
                display: '工作单位',
                name: 'workPlc',
                isSort: false,
                minWidth: 200
            },  */{
                display: '职位',
                name: 'pos',
                isSort: false,
                minWidth: 200
            },/*  {
                display: '单位电话',
                name: 'tel',
                isSort: false,
                minWidth: 200
            },  */{
                display: '证件类型',
                name: 'certTypCdNm',
                isSort: false,
                minWidth: 200
            }, {
                display: '证件号',
                name: 'certNo',
                isSort: false,
                minWidth: 140
            }, /* {
                display: '现居地址',
                name: 'homeAddr',
                isSort: false,
                minWidth: 140
            }, */ {
                display: '单位地址',
                name: 'workAddr',
                isSort: false,
                minWidth: 140
            },
				{
					display: '三要素检测结果',
					name: 'mpStsCdNm',
					isSort: false,
					minWidth: 140
				},
				{
					display: '活体检测结果',
					name: 'livAudStsCdNm',
					isSort: false,
					minWidth: 140
				}, {
                display: '操作',
                isSort: false,
                width: 100,
                render: function (rowdata, rowindex, value){
                    var h = "";
                    if(rowdata.rlTypCd != "7"){
                        h='<a class="sq-button-hasicon" href="javascript:deleteRow(';
                        h+="'"+rowdata.id+"'";
                        h+=",'ligergrid_A1'"
                        h+=")\"><i class=\"sqBtnIco_7\"></i>"+LogUtils.LOG_CMM_GRID_BTN_DELETE+"</a>"
                    }
                    return h;
                }
            }],
            pageSize:10,
            root:'rows',
            record:'total',
            hideLoadButton : true,
            width: '100%',
            isScroll: false,
            checkbox:true,
            rownumbers:true
        });
        npSocialRlGrid = liger.get("ligergrid_A1");
    };

    //新增社会关系
    function cstRlAddBtnEvent(){
        $("#cst_rl_add_btn").click(function(event) {
            //如果客户ID不存在是不能新增
            if(!cstId){
                UIUtils.alertWarning(LogUtils.LOG_CUST_CONFIRM_HERE_HAS_INFO);
                return; //验证不通过，不执行以下代码
            }

            $.ligerDialog.SQopen({
                width: 800,
                height:420,
                title : '社会关系/家庭成员',
                url:'<%=path%>/customer/cstnpsocialrl/toAddPage.do?cstId='+cstId,
                // 自定义buttons的时候 不要设置 fixButtons: true
                buttons: [{
                    text: "保存",  type: 'ok', cls: 'l-dialog-btn-ok',
                    onclick: function (item, Dialog) {
                        //在子页面里绑定 frameElement.dialog.onOk = function () {}
                        if (Dialog.onOk) Dialog.onOk();
                    }
                }, {
                    text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
                    onclick: function (item, Dialog) {
                        //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                        if (Dialog.onCancel) Dialog.onCancel();
                    }
                }
                ]
            });
        });
    };

    //修改社会关系
    function cstRlModifyBtnEvent(){
        $("#cst_rl_modify_btn").click(function(event) {
            //如果客户ID不存在是不能修改
            if(!cstId){
                UIUtils.alertWarning(LogUtils.LOG_CUST_CONFIRM_HERE_HAS_INFO);
                return; //验证不通过，不执行以下代码
            }

            var selectedRows = npSocialRlGrid.getSelectedRows();
            if(selectedRows.length != 1){
                UIUtils.alertWarning(LogUtils.LOG_CMM_SELECT_ONLY_A_ROW);
                return;
            }
            if(selectedRows[0].rlTypCd == "7"){
                UIUtils.alertWarning("本人数据不可修改！");
                return; //验证不通过，不执行以下代码
            }
            var _id = selectedRows[0].id;
            $.ligerDialog.SQopen({
                width: 800,
                height:420,
                title : '社会关系/家庭成员',
                url:'<%=path%>/customer/cstnpsocialrl/toAddPage.do?cstId='+cstId+'&rId='+_id,
                // 自定义buttons的时候 不要设置 fixButtons: true
                buttons: [{
                    text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
                    onclick: function (item, Dialog) {
                        //在子页面里绑定 frameElement.dialog.onOk = function () {}
                        if (Dialog.onOk) Dialog.onOk();
                    }
                }, {
                    text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
                    onclick: function (item, Dialog) {
                        //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                        if (Dialog.onCancel) Dialog.onCancel();
                    }
                }
                ]
            });
        });
    }

    //删除社会关系
    function deleteRow(rlId, gridId) {
        if(!cstId){
            UIUtils.alertWarning(LogUtils.LOG_CUST_ID_NOT_EMPTY);
            return;
        }

        $.ligerDialog.SQconfirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
            if(flag == false)return;

            var _url = "<%=path%>/customer/cstnpsocialrl/removeById.do";
            AjaxUtils.ajaxPost(_url, {id:rlId}, function(msg){
                if(msg.success == 1){
                    $.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
                    reloadCstRlGrid(cstId);
                }else{
                    $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
                }
            },true);
        });
    }

    //社会关系详细
    function cstRlDetailBtnEvent(_id){
        $.ligerDialog.SQopen({
            width: 800,
            height:420,
            title : '社会关系/家庭成员',
            url:'<%=path%>/customer/cstnpsocialrl/toDetailPage.do?rId='+_id,
            // 自定义buttons的时候 不要设置 fixButtons: true
            buttons: [{
                text: "关闭", type: 'cancel', cls: 'l-dialog-btn-no',
                onclick: function (item, Dialog) {
                    //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                    if (Dialog.onCancel) Dialog.onCancel();
                }
            }
            ]

        });
    }

    //加载客户关系数据
    function reloadCstRlGrid(_cstId){
        npSocialRlGrid.setParm("cstId",_cstId);
        npSocialRlGrid.reload();
    }

    //确定
    function  selectQd() {
        //如果客户ID不存在是不能修改
        var _cId = '${cstId}';
        if(!_cId){
            UIUtils.alertWarning(LogUtils.LOG_CUST_CONFIRM_HERE_HAS_INFO);
            return; //验证不通过，不执行以下代码
        }

        var selectedRows = npSocialRlGrid.getSelectedRows();
        if(selectedRows.length != 1){
            UIUtils.alertWarning(LogUtils.LOG_CMM_SELECT_ONLY_A_ROW);
            return;
        }

        var _id = selectedRows[0].id;
        var rlNm = selectedRows[0].rlNm;
        var mp = selectedRows[0].mp;
        var homeAddr = selectedRows[0].workAddr;//改为单位地址
        var rlTypCdNm = selectedRows[0].rlTypCdNm;

        var setDataByChild = GET_W2Wcallback();
        setDataByChild(rlNm,mp,homeAddr,rlTypCdNm,lkType);
        if(lkType == '2'){//联系人
            Remove_navTab('tab_custNpList_select${cstId}');
        }else if(lkType == '3'){//面谈人 rlTypCdNm
            Remove_navTab('tab_custNpList_rlnm${cstId}');
        }
    }
</script>
</body>
</html>